<?php
class interfaceController extends base
{
    public function __construct($type='api')
    {
        parent::__construct($type);
    }

    /**
     * ajax 创建俱乐部
     */
    public function doaddClub() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $name = trim(common::request('name','P','',true));
        $proviceName = common::request('provice','P','',true);
        $cityName = common::request('city','P','',true);
        $content = strip_tags(trim(common::request('content','P','',true)));

        if (!trim($name) || !trim($proviceName) ||!trim($cityName)) {
            $_ENV['error']->getErrors(101);
            exit;
        }
        if (!$_FILES || ($_FILES['myfile']['size'] == 0)) {
            $_ENV['error']->getErrors(101);
            exit;
        }

        $status = $this->load('paome/paomeClub')->checkClubName($name);
        if ($status < 0) {
            $errorMap = array('-1'=>6001,'-2'=>6003,'-3'=>6002);//错误码映射
            $_ENV['error']->getErrors($errorMap[$status]);
            exit;
        }
        if ($content) {
            $contentStatus = $this->load('paome/paomeClub')->checkClubContent($content);
            if ($contentStatus < 0) {
                $errorMap = array('-1'=>6004,'-2'=>6003);//错误码映射
                $_ENV['error']->getErrors($errorMap[$contentStatus]);
                exit;
            }
        }

        $imageName ='paomeWeb_clubHeader_'.md5(microtime(TRUE).$_FILES['myfile']['name']);
        $image_url = $this->load('qiniu')->uploadQiNiuImg('myfile',$imageName);
        if (!$image_url) {
            $_ENV['error']->getErrors(6008);
            exit;
        }
        //创建俱乐部检测
        $canCreateClub = $this->load('paome/paomeClub')->getUserCanCreateClub($uid);
        if ($canCreateClub == -1) {
            $_ENV['error']->getErrors(6009);
            exit;
        } else if($canCreateClub == -2) {
            $_ENV['error']->getErrors(6005);
            exit;
        } else if($canCreateClub == -3){
            $_ENV['error']->getErrors(6006);
            exit;
        } else if($canCreateClub == -4) {
            $_ENV['error']->getErrors(6009);
            exit;
        }

        //消耗正能量
        $boolEnergy = $this->load('paome/home')->expendEnergy($uid);
        if (!$boolEnergy) {
            $_ENV['error']->getErrors(6007);
            exit;
        }
        //开始创建
        $result = $this->load('paome/paomeClub')->addClub(array(
            'proviceName'=>$proviceName,
            'cityName'=>$cityName,
            'title'=>$name,
            'image'=>$image_url,
            'content'=>$content,
            'uid'=>$uid,
            'joinRoundsNum'=>$canCreateClub
        ));
        $this->result['result']['is_success'] = 0;
        if ($result) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     * 查询预热期第一轮开始时间剩余时间
     */
    public function dogetPaomeSyTime() {
        $this->printResult = TRUE;
        $nowTime = time();
        $startTime = $this->db->getOne("select start_time from r_pm_contest where  start_time > $nowTime ORDER BY start_time asc limit 1");
        if (!$startTime) {
            $this->result['result']['time'] = 0;
            exit;
        }
        $this->result['result']['time'] = bcsub($startTime,$nowTime);
    }

    /**
     * 查询赛季轮次列表
     */
    public function dogetPaomeRoundListApi() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $result = array('roundList'=>[]);
        $arrPaome = $this->db->getRow("select id,status from r_pm_contest where flag=1");
        if (!$arrPaome)  {
            $this->result['result'] = $result;
        }
        $roundsDict = common::$roundsDict;
        $roundId = 1;
        foreach ($roundsDict as $k =>$v) {
            if (in_array($arrPaome['status'], $v)) {
                $roundId = $k;
            }
        }

        $arrPaome = $this->db->getRow("select id,status from r_pm_contest where flag=1");
        if(!$arrPaome) {
           return $result;
        }
        $arrRound = $this->db->getAll("select type from r_pm_rounds where contest_id={$arrPaome['id']} and status=0");
        if (!$arrRound)  {
            $this->result['result'] = $result;
        }

        $list= [];
        foreach ($arrRound as $key=>$val) {
            switch($val['type']) {
                case $val['type'] <=12:
                    if (!array_key_exists(1,$list)) {
                        $list[1] = array('roundId'=>1,'title'=>'第一轮','isCurrent'=> $roundId==1 ? 1: 0);
                    }
                    break;
                case $val['type'] >12 && $val['type'] <=22:
                    if (!array_key_exists(5,$list)) {
                        $list[5] =array('roundId'=>5,'title'=>'第二轮','isCurrent'=>$roundId==5 ? 1: 0);
                    }
                    break;
                case $val['type'] >22 && $val['type'] <=32:
                    if (!array_key_exists(5,$list)) {
                        $list[10] =array('roundId'=>10,'title'=>'第三轮','isCurrent'=>$roundId==10 ? 1: 0);
                    }
                    break;
                case $val['type'] >=105 && $val['type'] <=106:
                    if (!array_key_exists(100,$list)) {
                        $list[100] =array('roundId'=>100,'title'=>'冠军争霸赛','isCurrent'=>$roundId==100 ? 1: 0);
                    }
                    break;
                default:
                    break;
            }
        }
        $this->result['result'] = array('roundList'=>$list);
    }

    /**
     * 查询当前轮次
     */
    public function dogetCurrentRoundIdApi() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $result = array('roundId'=>1);
        $arrPaome = $this->db->getRow("select id,status from r_pm_contest where flag=1");
        if (!$arrPaome)  {
            $this->result['result'] = $result;
        }
        $roundsDict = common::$roundsDict;
        $roundId = 1;
        foreach ($roundsDict as $k =>$v) {
            if (in_array($arrPaome['status'], $v)) {
                $roundId = $k;
            }
        }
        $result['roundId'] = $roundId;
       $this->result['result'] = $result;
    }

    /**
     * 查询排行榜数据
     */
    public function dogetRankForH5() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $result = array('total'=>0,'list'=>[]);
        $paomeId = (int)common::request('paomeId', 'G', 0, true);
        if (!$paomeId) {
            //查询当前的赛季
            $paomeInfo = $this->load('paome/cup')->getCurrentPaomeInfo();
            if (!$paomeInfo) {
                $this->result['result']= $result;
                exit;
            }
            $paomeId = $paomeInfo['id'];
        }
        $roundId = (int)common::request('roundId', 'G', 1, true);
        $typeWd = (int)common::request('typeWd', 'G', 1, true);
        $clubName = common::request('clubName', 'G', '', true);
        $rankModel = $this->load('paome/rank');
        if ($roundId == 100) {
            $list = $rankModel->getRankForH5New($paomeId,$roundId,$typeWd,$uid,$clubName);
        } else {
            $list = $rankModel->getRankForH5($paomeId,$roundId,$typeWd,$uid,$clubName);
        }
        $this->result['result'] = array('total'=>$rankModel->total,'list'=>$list);
    }

    /**********************************************消息 start*********************************************/
    /**
     * 查询消息列表
     */
    public function dogetPaomeMsgList() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $mid = common::request('mid','G',0 ,true);
        $offset = common::request('offset','G',20,true);
        $messagePmModel = $this->load('paome/messagePm');
        $list = $messagePmModel->getMsgList(array('uid'=>$uid, 'mid'=>$mid, 'offset'=>$offset));
        $result = [];
        if ($list) {
            $arrDesc = $messagePmModel->descType;
           foreach ($list as $key=>$val) {
               $pushContentDesc = $messagePmModel->getPushContent(array(
                   'descType'=>$val['desc_type'],
                   'sourceId'=>$val['source_id'],
               ));//消息内容

               //消息状态
               $result[$key]['id'] = $val['id'];
               $result[$key]['content'] = $pushContentDesc;
               $result[$key]['status'] = $val['status'];
               $result[$key]['descType'] = $val['desc_type'];
               $objectInfo = [];
               switch($val['desc_type']) {
                   case 'P1':
                   case 'P2':
                       $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['source_id'],'nickname');
                       $header   = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['source_id'],'header');
                       $objectInfo = array('id'=>$val['source_id'], 'header'=>$header, 'name'=>$nickname);
                       break;
                   case 'P3':
                   case 'P4':
                       $arrClubInfo = $this->load('paome/paomeClub')->getClubInfo($val['source_id'],'title,image');
                       $objectInfo = array('id'=>$val['source_id'], 'header'=>$arrClubInfo['image'], 'name'=>$arrClubInfo['title']);
                       break;
               }
               $result[$key]['objectInfo'] = $objectInfo;
           }
        }
        $this->result['result'] = array('total'=>$messagePmModel->total,'list'=>$result);
    }

    /**
     * 查询未读消息数量
     */
    public function dogetMsgNoReadNum() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $num = 0;
        if ($uid) {
            $num = $this->load('paome/messagePm')->getMsgNum($uid, 0);
        }
        $this->result['result']['num'] = $num;
    }

    /**
     * 更新消息为已读
     */
    public function dosetMsgIsRead() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(101);exit;
        }
        $result = $this->load('paome/messagePm')->setMsgIsRead($uid);
        $this->result['result']['is_success'] = 1;
    }

    /**********************************************消息 end*********************************************/

    /**********************************************战队 start**************************************************/
    /**
     * 战队列表---第一期 要改
     */
    public function dogetClubList1() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $page = common::request('page','G', 1 ,true);
        $offset = common::request('offset','G',20,true);
        $start = ($page - 1) * $offset;
        $arrPaomeInfo = $this->load('paome/cup')->getCurrentPaomeInfo();
        if (!$arrPaomeInfo) {
            $this->result['result'] = array('total'=>0,'list'=>[]);exit;
        }
        $clubModel = $this->load('paome/paomeClub');
        $list = $this->load('paome/paomeClub')->getClubListForApp(array(
            'start'=>$start,
            'offset'=>$offset,
            'uid'=>$uid
        ));
        $result = [];
        if ($list) {
            $arrId = [];
            if ($uid) {
                //用户所在俱乐部
                $arrExistClub = $this->db->getAll("select club_id,status from r_pm_club_users where uid=$uid and status in(0,-1)");
                if ($arrExistClub) {
                    foreach ($arrExistClub as $key=>$val) {
                        $arrId[$val['club_id']] = $val['status'];
                    }
                }
            }
            foreach($list as $key =>$val) {
                $result[$key]['status'] = 0;
                if ($arrId && isset($arrId[$val['id']])) {
                    if ($arrId[$val['id']] == -1) {
                        $result[$key]['status'] = 1;//待审核
                    } else if ($arrId[$val['id']] == 0) {
                        $result[$key]['status'] = 2;//已加入
                    }
                }
                $result[$key]['id']  = $val['id'];
                $result[$key]['title']= $val['title'];
                $result[$key]['image']= $val['image'];
                $result[$key]['userNum']= $val['user_num'];
                $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['head_uid'], 'header');
                $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['head_uid'], 'nickname');
                $result[$key]['leaderId']  = $val['head_uid'];
                $result[$key]['nickname']  = $nickname;
                $result[$key]['leaderImage']  = $header;
                $result[$key]['leaderIntroduce']  = $val['head_introduce'];
            }
        }
        $this->result['result'] = array('total'=>$clubModel->total,'list'=>$result);
    }

    public function dogetClubList() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $arrPaomeInfo = $this->load('paome/cup')->getCurrentPaomeInfo();
        if (!$arrPaomeInfo) {
            $this->result['result'] = array('total'=>0,'list'=>[],'cnt'=>array('isgameCnt'=>0,'gameOverCnt'=>0));exit;
        }
        $clubName = common::request('clubName', 'G', '', true);
        $userNumOrder = common::request('userNumOrder', 'G', 0, true);
        $statusOrder = common::request('statusOrder', 'G', 0, true);

        $page = common::request('page','G', 1 ,true);
        $offset = common::request('offset','G',20,true);
        $start = ($page - 1) * $offset;
        $clubModel = $this->load('paome/paomeClub');
        $list = $this->load('paome/paomeClub')->getClubListForApp2(array(
            'start'=>$start,
            'offset'=>$offset,
            'uid'=>$uid,
            'clubName'=>$clubName,
            'userNumOrder'=>$userNumOrder,
            'statusOrder'=>$statusOrder,
            'paomeId'=>$arrPaomeInfo['id']
        ));
        $result = [];
        if ($list) {
            $arrId = [];
            if ($uid) {
                //用户所在俱乐部
                $arrExistClub = $this->db->getAll("select club_id,status from r_pm_club_users where uid=$uid and status in(0,-1)");
                if ($arrExistClub) {
                    foreach ($arrExistClub as $key=>$val) {
                        $arrId[$val['club_id']] = $val['status'];
                    }
                }
            }

            //当前轮次阶段
            $roundId2 = $this->load('paome/cup')->getRoundId($arrPaomeInfo['status'], 2);
            //用户所在俱乐部
                foreach($list as $key =>$val) {
                    $result[$key]['status'] = 0;
                    if ($arrId && isset($arrId[$val['id']])) {
                        if ($arrId[$val['id']] == -1) {
                            $result[$key]['status'] = 1;//待审核
                        } else if ($arrId[$val['id']] == 0) {
                            $result[$key]['status'] = 2;//已加入
                        }
                    }
                $result[$key]['id']  = $val['id'];
                $result[$key]['title']= $val['title'];
                $result[$key]['image']= $val['image'].'?imageView2/2/w/128/h/128';
                $result[$key]['userNum']= $val['user_num'];
                $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['head_uid'], 'header');
                $result[$key]['leaderId']  = $val['head_uid'];
                $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['head_uid'], 'nickname');
                $result[$key]['nickname']  = $nickname;
                $result[$key]['leaderImage']  = $header;
                $result[$key]['leaderIntroduce']  = $val['head_introduce'];
                $result[$key]['tagList'] = [];
                //标签 推荐原因
                $tagList = array(
                    'top'=>array('tagId'=>1,
                        'tagContent'=>'休养生息为争霸赛备战',
                        'reason'=>array('精英战队，团员综合能力偏高')
                    ),
                    'one'=>array('tagId'=>2,
                        'tagContent'=>'满足%s人就可以比赛啦',
                        'reason'=>array(
                            '优质战队，团长带队经验丰富',
                            '只要再来 %s 人就可以参与竞赛啦'
                        )
                    ),
                    'two'=>array('tagId'=>3,
                        'tagContent'=>'竞赛开始即可进行比赛',
                        'reason'=>array(
                            '竞赛一旦开始就可以和所有参与者一较高下',
                            '竞赛马上开始，就差你啦'
                        )
                    ),
                    'three'=>array('tagId'=>4,
                        'tagContent'=>'竞赛正在进行中',
                        'reason'=>array(
                            '战队正在竞赛中，加入即可开始比赛',
                        )
                    ),
                    'four'=>array('tagId'=>5,
                        'tagContent'=>'第%s轮竞赛招贤纳才',
                        'reason'=>array(
                            '备战时间充裕',
                        )
                    )
                );
                if (isset($val['topId'])) {
                    $result[$key]['tagList'] = $tagList['top'];
                }  else {
                    switch($val['bType']) {
                        case 1:
                            switch ($val['bStatus']) {
                                case 0: //预赛报名
                                    if ($val['user_num'] < $arrPaomeInfo['min_num']) {
                                        $tagList['one']['tagContent'] = vsprintf($tagList['one']['tagContent'],array($arrPaomeInfo['min_num']));
                                        $tagList['one']['reason'][1] = vsprintf($tagList['one']['reason'][1],array($arrPaomeInfo['min_num']-$val['user_num']));
                                        $result[$key]['tagList'] = $tagList['one'];
                                    }  else {
                                        $result[$key]['tagList'] = $tagList['two'];
                                    }
                                    break;
                                case 15: //预赛竞赛中
                                case 20: //预赛空档期
                                    $result[$key]['tagList'] = $tagList['three'];
                                    break;
                            }
                            break;
                        case 10:
                        case 20:
                            switch ($val['bStatus']) {
                                case 0: //报名
                                    if ($roundId2 == $val['bStatus']) { //当前阶段
                                        if ($val['user_num'] < $arrPaomeInfo['min_num']) {
                                            $tagList['one']['tagContent'] = vsprintf($tagList['one']['tagContent'],array($arrPaomeInfo['min_num']));
                                            $tagList['one']['reason'][1] = vsprintf($tagList['one']['reason'][1],array($arrPaomeInfo['min_num']-$val['user_num']));
                                            $result[$key]['tagList'] = $tagList['one'];
                                        }  else {
                                            $result[$key]['tagList'] = $tagList['two'];
                                        }
                                    } else {
                                        $roundId2 = $this->load('paome/cup')->getRoundId($arrPaomeInfo['status'], 1);
                                        $arrRoundFormart = array(1=>'一',10=>'二',20=>'三');
                                        if ($arrRoundFormart[$roundId2]) {
                                            $tagList['four']['tagContent'] = vsprintf($tagList['four']['tagContent'],array($arrRoundFormart[$roundId2]));
                                            $result[$key]['tagList'] = $tagList['four'];
                                        }
                                    }
                                    break;
                                case 15: //竞赛中
                                case 20: //空档期
                                    $result[$key]['tagList'] = $tagList['three'];
                                    break;
                            }
                            break;
                    }
                }
                //标签

            }
        }

        //招募中的战队数量
        $maxNum = $arrPaomeInfo['max_num'];
        $cnt1 = $this->db->getOne("select count(1) from r_pm_club where user_num < $maxNum and status=0");
        //招募结束的战队数量
        $cnt2 = $this->db->getOne("select count(1) from r_pm_club where user_num = $maxNum and status=0");
        $this->result['result'] = array('total'=>$clubModel->total,'list'=>$result ,'cnt'=>array('isgameCnt'=>$cnt1,'gameOverCnt'=>$cnt2));
    }

    /**
     * 战队详情---第一期要改
     */
    public function dogetClubDetailApi1() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $clubId = common::request('clubId', 'G', 0 ,true);
        if (!$clubId) {
            $_ENV['error']->getErrors(101);
            exit;
        }
        $info = $this->load('paome/paomeClub')->getClubInfo($clubId);
        $result = [];
        if ($info) {
            $result['id'] = $info['id'];
            $result['proviceName'] = $info['provice_name'];
            $result['cityName'] = $info['city_name'];
            $result['title'] = $info['title'];
            $result['image'] = $info['image']? $info['image'].'?imageView2/2/w/128/h/128' : '';
            $result['content'] = $info['content'];
            $result['formatTime'] = date('Y-m-d',$info['create_time']);
            $result['userNum'] = $info['user_num'];
            $result['isLeader'] = 0;
            $result['userStatus'] = 0; //未加入
            if ($uid) {
                $result['isLeader'] = ($info['head_uid'] == $uid) ? 1 : 0;
                if ($info['head_uid'] == $uid) {
                    $result['userStatus'] = 2;
                } else {
                    $sql = "select id,status from r_pm_club_users where uid= $uid and club_id={$info['id']} and status in(0,-1) ";
                    $arr = $this->db->getRow($sql);
                    if ($arr) {
                        if ($arr['status'] == 0) {
                            $result['userStatus'] = 2;
                        } else { //待审核
                            $result['userStatus'] = 1;
                        }
                    }
                }
            }
        }
        $this->result['result']['info'] = $result;
    }

    /**
     * 战队详情
     */
    public function dogetClubDetailApi() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $clubId = common::request('clubId', 'G', 0 ,true);
        if (!$clubId) {
            $_ENV['error']->getErrors(101);
            exit;
        }
        $result = $this->load('paome/paomeClub')->getClubDetailApi2(array(
            'clubId'=>$clubId,
            'uid'=>(int)$uid
        ));
        $this->result['result'] = $result;
    }

    /**
     * 战队成员列表---第一期要改
     */
    public function dogetClubUserListApi() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        $clubId = common::request('clubId', 'G', 0 ,true);
        if (!$clubId) {
            $_ENV['error']->getErrors(101);
            exit;
        }
        $page = common::request('page','G', 1 ,true);
        $offset = common::request('offset','G',50,true);
        $start = ($page - 1) * $offset;
        $paomeClubModel = $this->load('paome/paomeClub');
        $list  = $paomeClubModel->getClubUserListForApp(array(
            'start'=>$start,
            'offset'=>$offset,
            'clubId'=>$clubId,
        ));
        $result =[];
        if ($list) {
            foreach ($list as $key=>$val) {
                $header = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'], 'header');
                $nickname = $this->redis->hget(REDIS_PREFIX . 'UserInfo_' . $val['uid'], 'nickname');
                $result[$key]['uid'] = $val['uid'];
                $result[$key]['header'] = $header;
                $result[$key]['nickname'] = $nickname;
                $result[$key]['isLeader'] = $val['level'] == 5 ? 1 : 0;
                $result[$key]['leaderIntroduce'] = '';
                if ($val['level'] == 5) {
                    $result[$key]['leaderIntroduce'] = $this->db->getOne("select head_introduce from r_pm_club where id={$val['club_id']}");
                }
            }
        }
        $this->result['result'] = array('total'=>$paomeClubModel->total,'list'=>$result);
    }

    /**
     * 战队成员列表
     */
    public function dogetClubUserListApi2() {

    }


    /**
     * 申请加入俱乐部
     */
    public function dojoinClub() {
        $this->printResult = TRUE;
        $uid = $this->uid;//fromUid
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $clubId = common::request('clubId','P',0,true);
        if (!$clubId) {
            $_ENV['error']->getErrors(101);
            exit;
        }
        $status = $this->load('paome/paomeClub')->joinClub($uid, $clubId);
        if ($status<0) {
            $errorMap = array('-1'=>6012,'-2'=>6013,'-3'=>6014, '-4'=>6015, '-5'=>6016, '-6'=>6017, '-7'=>6018);//错误码映射
            $_ENV['error']->getErrors($errorMap[$status]);
            exit;
        }
        $this->result['result']['is_success'] = 0;
        if ($status) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     * 同意加入俱乐部
     */
    public function doagreeJoin() {
        $this->printResult = TRUE;
        $uid = $this->uid;//fromUid
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $mid = common::request('mid','P',0,true);
        if (!$mid) {
            $_ENV['error']->getErrors(101);
            exit;
        }
        $status = $this->load('paome/paomeClub')->agreeJoin($uid, $mid);
        if ($status<0) {
            $errorMap = array('-1'=>6016,'-2'=>6019,'-3'=>6026,
                                '-4'=>6012,'-5'=>6013,'-6'=>6017,
                                '-7'=>6022,'-8'=>6014,'-9'=>6018,
                                '-10'=>6021,'-11'=>6026);//错误码映射
            $_ENV['error']->getErrors($errorMap[$status]);
            exit;
        }
        $this->result['result']['is_success'] = 0;
        if ($status) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     *退出俱乐部
     */
    public function dooutClub() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $status = $this->load('paome/paomeClub')->outJoin($uid);
        if ($status<0) {
            $errorMap = array('-1'=>6016,'-2'=>6017,'-3'=>6012,
                '-4'=>6013,'-5'=>6022,'-6'=>6023,
                '-7'=>6022);//错误码映射
            $_ENV['error']->getErrors($errorMap[$status]);
            exit;
        }
        $this->result['result']['is_success'] = 0;
        if ($status) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     * 移除用户
     */
    public function dooutUsers() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $toUid = common::request('toUid','P',0,true);
        if (!$toUid) {
            $_ENV['error']->getErrors(101);
            exit;
        }
        $status = $this->load('paome/paomeClub')->outUsers($uid, $toUid);
        if ($status<0) {
            $errorMap = array('-1'=>6016,'-2'=>6012,'-3'=>6017, '-4'=>6023, '-5'=>6022);//错误码映射
            $_ENV['error']->getErrors($errorMap[$status]);
            exit;
        }
        $this->result['result']['is_success'] = 0;
        if ($status) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     * 解散俱乐部
     */
    public function dokillClub() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $status = $this->load('paome/paomeClub')->killClub($uid);
        if ($status<0) {
            $errorMap = array('-1'=>6016,'-2'=>6012,'-3'=>6017,
                '-4'=>6024,'-5'=>6025,'-6'=>6022);//错误码映射
            $_ENV['error']->getErrors($errorMap[$status]);
            exit;
        }
        $this->result['result']['is_success'] = 0;
        if ($status) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     * 增加团长介绍
     */
    public function doaddClubLeaderIntroduce() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $introduce = strip_tags(htmlspecialchars(common::request('introduce', 'P', '' ,true)));
        $r = $this->db->update("update r_pm_club set head_introduce='$introduce' where head_uid=$uid and status=0");
        $this->result['result']['is_success'] = 0;
        if ($r) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     * 报名下一轮(目前支持2轮)
     */
    public function doclubSignUpGame() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $status = $this->load('paome/paomeClub')->clubSignUpGame($uid);
        if ($status<0) {
            $errorMap = array('-1'=>6016,'-2'=>6028,'-3'=>6012);//错误码映射
            $_ENV['error']->getErrors($errorMap[$status]);
            exit;
        }
        $this->result['result']['is_success'] = 0;
        if ($status) {
            $this->result['result']['is_success'] = 1;
        }
    }

    /**
     * 查询首页用户前后轮战队信息
     */
    public function dogetHomeClubRankList() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $result = $this->load('paome/paomeClub')->getUserClubNextPreList($uid);

        $this->result['result']['list'] = $result;
    }

    /**
     * 获取战队证书详情
     */
    public function dogetClubCertificate() {
        $this->printResult = TRUE;
        $clubId = common::request('clubId','R',0);//俱乐部ID
        if (!$clubId) {
            common::tips('参数丢失');exit;
        }
        //获取当前赛季
        $paomeInfo = $this->load('paome/cup')->getCurrentPaomeInfo();
        if (!$paomeInfo) {
            common::tips('当前没有赛季信息');exit;
        }
        $paomeId = $paomeInfo['id'];
        $certificate = array();
        //查询俱乐部
        $clubInfo = $this->load('paome/paomeClub')->getClubInfo($clubId);
        if(!empty($clubInfo) && $clubInfo['status'] == 0){
            $data = $this->load('paome/paomeClub')->getClubCertificate($paomeId, $clubId);
            if($data){
                $i = 0;
                foreach ($data as &$v) {
                    $certificate[$i]['clubName'] = $clubInfo['title'];
                    $certificate[$i]['type'] = $v['type'];
                    $certificate[$i]['type_wd'] = $v['type_wd'];
                    $certificate[$i]['rank_num'] = $v['rank_num'];
                    $certificate[$i]['rank_value'] = $v['rank_value'];
                    $certificate[$i]['mileage_score'] = $v['mileage_score'];
                    $certificate[$i]['speed_score'] = $v['speed_score'];
                    $certificate[$i]['support_score'] = $v['support_score'];
                    //获取战队明星成员数据
                    $certificate[$i]['starUser'] = $this->load('paome/paomeClub')->getClubMemberList($paomeId, $v['type'], $clubId);
                    $i++;
                }
            }
        }else{
            common::tips('不存在该俱乐部');exit;
        }

        $this->result['result']['certificate'] = $certificate;
    }

    /**
     * 关闭页面顶部引导分享
     */
    public function docloseTop() {
        $this->printResult = TRUE;
        $uid = $this->uid;
        if (!$uid) {
            $_ENV['error']->getErrors(201);
            exit;
        }
        $date = date('Ymd');
        $this->redis->set(REDIS_PREFIX . "paomeIsTop_" . $date . "_uid_" . $uid, 1);
        $this->redis->expire(REDIS_PREFIX . "paomeIsTop_" . $date . "_uid_" . $uid, 86400);
    }

    /**********************************************战队 end**************************************************/

}
